package com.tvsinfo.jdk.demo.case6_higher_order_function.order;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum PayStatusEnum {
    TODO(101, 0, "todoPay", "未支付"),                  // 未支付
    PAYED(201, 1, "payed", "已支付");                   // 已支付

    private Integer key;
    private Integer oldKey;
    private String desc;
    private String cnDesc;

    private static final Map<Integer, PayStatusEnum> PAY_STATUS_ENUM_MAP = new HashMap<>();
    private static final Map<Integer, List<PayStatusEnum>> oldPayStatusEnumMap= new HashMap<>();

    static {
        for (PayStatusEnum _tmp : PayStatusEnum.values()) {
            List<PayStatusEnum> orderStatusEnums = oldPayStatusEnumMap.get(_tmp.oldKey);
            if (null == orderStatusEnums) {
                orderStatusEnums = new ArrayList<>();
                oldPayStatusEnumMap.put(_tmp.oldKey, orderStatusEnums);
            }
            orderStatusEnums.add(_tmp);

            if (null != PAY_STATUS_ENUM_MAP.get(_tmp.key)) {
                continue;
            }
            PAY_STATUS_ENUM_MAP.put(_tmp.key, _tmp);
        }

    }

    PayStatusEnum(Integer key, Integer oldKey, String desc, String cnDesc) {
        this.key = key;
        this.oldKey = oldKey;
        this.desc = desc;
        this.cnDesc = cnDesc;
    }

    public static PayStatusEnum getByKey(Integer key) {
        if (null == key) {
            return null;
        }
        return PAY_STATUS_ENUM_MAP.get(key);
    }

    /**
     * 根据老的Key获得
     * create by Ruyi.Song on 2018/8/16 16:55
     */
    public static List<PayStatusEnum> getByOldKey(Integer oldKey) {
        if (null == oldKey) {
            return null;
        }
        List<PayStatusEnum> payStatusEnums = oldPayStatusEnumMap.get(oldKey);
        return payStatusEnums;
    }

    public Integer getOldKey() {
        return oldKey;
    }

    public Integer getKey() {
        return this.key;
    }

    public String getDescription() {
        return this.desc;
    }

    public String getCnDesc() {
        return cnDesc;
    }

    @Override
    public String toString() {
        return "PayStatusEnum{" +
                "key=" + key +
                ", desc='" + desc + '\'' +
                ", cnDesc='" + cnDesc + '\'' +
                '}';
    }
}